package com.example.projectmanagement.repository.study;

import com.example.projectmanagement.model.study.AnswerLike;
import com.example.projectmanagement.model.study.Answer;
import com.example.projectmanagement.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.Optional;

@Repository
public interface AnswerLikeRepository extends JpaRepository<AnswerLike, Long> {
    Optional<AnswerLike> findByAnswerAndUser(Answer answer, User user);
    
    @Query("SELECT COUNT(al) FROM AnswerLike al WHERE al.answer.id = :answerId")
    Integer countByAnswerId(@Param("answerId") Long answerId);
    
    void deleteByAnswer(Answer answer);
}